home *** CD-ROM | disk | FTP | other *** search
- $[// SAMPLE.DCG - Sample dCG Script for Generic SDK Application]$
- $[// rncbc (c) 1996, Copyright by Rui Capela]$
- $[//****************************************]$
- $[//*** Application Specification Dialog ***]$
- $[//****************************************]$
- $[dialog AppGenDlg, "New Application", 50, 50, 198, 172]$
- $[control NameLbl, Text, "Application &Name:", 4, 4, 64, 8]$
- $[control AppName, Edit, "", 4, 14, 64, 12]$
- $[control TargetLbl, Text, "Tar&get:", 72, 4, 66, 8]$
- $[control Target, DropListBox, "", 72, 14, 66, 32]$
- $[control DirLbl, Text, "&Directory:", 4, 30, 134, 8]$
- $[control AppDir, Edit, "", 4, 40, 134, 12]$
- $[control Browse, PushButton, "&Browse...", 148, 40, 46, 14]$
- $[control TitleLbl, Text, "&Title:", 4, 56, 190, 8]$
- $[control AppTitle, Edit, "", 4, 66, 190, 12]$
- $[control VersLbl, Text, "&Version:", 4, 82, 30, 8]$
- $[control AppVersid, Edit, "", 4, 92, 30, 12]$
- $[control AuthLbl, Text, "&Author:", 38, 82, 156, 8]$
- $[control AppAuthor, Edit, "", 38, 92, 156, 12]$
- $[control InfoLbl, Text, "&Info:", 4,108, 190, 8]$
- $[control AppInfo, MLEdit, "", 4,118, 190, 50]$
- $[control Ok, OkButton, "OK", 148, 4, 46, 14]$
- $[control Cancel, CancelButton, "Cancel", 148, 22, 46, 14]$
- $[end dialog]$
- $[AppGenDlg.Target.Items = list("Windows 3.x", "Win32")]$
- $[//*** Application Info (Default) ***]$
- $[AppName = "App1"]$
- $[AppDir = curdir()]$
- $[AppVersid = "0.01a"]$
- $[AppTitle = AppName + " Application"]$
- $[AppAuthor = "rncbc"]$
- $[AppInfo = "Written by: " + AppAuthor]$
- $[AppCopyright = "Copyright (c) " + left(date(), 4) + ", " + AppAuthor]$
- $[// *** Application Definition Persistence ***]$
- $[SaveFile = dcgdir() + "\Sample.sav"]$
- $[if exist(SaveFile)]$
- $[AppGenDlg = loaditem(SaveFile)]$
- $[if (!isobject(AppGenDlg))]$
- $[msgbox("Error", "The dialog settings could not be loaded from " + SaveFile, 16)]$
- $[return]$
- $[endif]$
- $[else]$
- $[//*** Application Dialog Loop ***]$
- $[AppGenDlg.AppName.Text = AppName]$
- $[AppGenDlg.AppDir.Text = AppDir]$
- $[AppGenDlg.AppTitle.Text = AppTitle]$
- $[AppGenDlg.AppVersid.Text = AppVersid]$
- $[AppGenDlg.AppAuthor.Text = AppAuthor]$
- $[AppGenDlg.AppInfo.Text = AppInfo.replace("\n", chr(13) + chr(10))]$
- $[endif // !exist]$
- $[// *** Application Dialog Loop ***]$
- $[Done = FALSE]$
- $[while (!Done)]$
- $[dialog AppGenDlg]$
- $[if (!AppGenDlg.Result)]$
- $[return]$
- $[endif]$
- $[// Browse button has been selected?]$
- $[if (AppGenDlg.Browse.Select)]$
- $[Dir = DirDialog("New Application Directory")]$
- $[if (Dir != "")]$
- $[AppGenDlg.AppDir.Text = Dir]$
- $[endif]$
- $[else]$
- $[// Validate dialog results.]$
- $[AppGenDlg.AppName.Text.strip().left(8)]$
- $[AppGenDlg.AppDir.Text.trim()]$
- $[select]$
- $[case AppGenDlg.AppName.Text = ""]$
- $[MsgBox("New Application", "Invalid Application Name.", 48)]$
- $[case AppGenDlg.AppDir.Text = ""]$
- $[MsgBox("New Application", "Invalid Application Directory.", 48)]$
- $[otherwise]$
- $[Done = TRUE]$
- $[endselect]$
- $[endif]$
- $[end while]$
- $[//*** Application Info (from dialog) ***]$
- $[AppName = AppGenDlg.AppName.Text]$
- $[AppDir = AppGenDlg.AppDir.Text]$
- $[AppTitle = AppGenDlg.AppTitle.Text]$
- $[AppInfo = AppGenDlg.AppInfo.Text]$
- $[AppInfo.replace(chr(13) + chr(10), "\n")]$
- $[//*** Application Path (include trailing slash) ***]$
- $[AppPath = AppDir]$
- $[if right(AppPath, 1) != "\"]$
- $[AppPath = AppPath + "\"]$
- $[endif]$
- $[//*** Filenames to be generated ***]$
- $[AppHdrFile = AppName + ".h" // Main application header file]$
- $[AppSrcFile = AppName + ".c" // Main application source file]$
- $[AppRrcFile = AppName + ".rc" // Resource file]$
- $[AppDefFile = AppName + ".def" // Definition file]$
- $[//*******************************************]$
- $[//*** Common source file header Procedure ***]$
- $[//*******************************************]$
- $[procedure AppHeader ( name, lbegin )]$
- $[lbegin]$
- $[pad(lbegin, 4) + pad(upper(name), 12)]$ $[AppTitle]$
- $[pad(lbegin, 16)]$ Version $[AppVersid]$
- $[lbegin]$
- $[pad(lbegin, 16)]$ $[AppCopyright]$
- $[pad(lbegin, 16)]$ All rights reserved.
- $[lbegin]$
- $[pad(lbegin, 4)]$Generated by dCG v$[dcgversion()]$ on $[picture(date(), "@Ddd-mm-yyyy")]$ $[time()]$.
- $[lbegin]$
- $[return]$
- $[end procedure]$
- $[//************************************]$
- $[//*** Main application header file ***]$
- $[//************************************]$
- $[output AppPath + AppHdrFile]$
- $[AppHeader(AppHdrFile, "/" + "/")]$
- // Main $[AppName]$ application header file.
- //
-
- #ifndef __$[upper(AppName)]$_H
- #define __$[upper(AppName)]$_H
-
- // Common includes.
- #include <windows.h>
-
- //
- // Application Resource Identifiers.
- //
-
- // Accelerator id.
- #define IDA_$[upper(AppName)]$ACCEL 100
-
- // Menu ids.
- $[MenuID = 100]$
- #define IDM_$[upper(AppName)]$MENU $[MenuID]$
-
- $[ItemID = 101]$
- #define IDM_FILEEXIT $[ItemID]$
- $[ItemID = ItemID + 1]$
- #define IDM_HELPABOUT $[ItemID]$
-
-
- //
- // Dialog related ids.
- //
-
- $[DlgID = 100]$
- #define IDD_$[upper(AppName)]$ABOUT $[DlgID]$
-
- $[CtlID = 101]$
- #define IDC_$[upper(AppName)]$ABOUTNAME $[CtlID]$
- $[CtlID = CtlID + 1]$
- #define IDC_$[upper(AppName)]$ABOUTCOMPANY $[CtlID]$
- $[CtlID = CtlID + 1]$
- #define IDC_$[upper(AppName)]$ABOUTBUILD $[CtlID]$
-
- // $[PROTECT AppName + "UserDefs"]$
- // User Definitions.
- // $[ENDPROTECT]$
-
- #endif // __$[upper(AppName)]$_H
-
- // end of $[upper(AppHdrFile)]$
- $[//************************************]$
- $[//*** Main application source file ***]$
- $[//************************************]$
- $[output AppPath + AppSrcFile]$
- $[AppHeader(AppSrcFile, "/" + "/")]$
- // Main $[AppName]$ application source file.
- //
-
- #include "$[AppHdrFile]$"
-
- // Stuff passed in WinMain.
- HINSTANCE g_hInstance = 0;
- HINSTANCE g_hPrevInstance = 0;
- LPSTR g_lpszCmdLine = 0;
- int g_nCmdShow = 0;
-
- // Main window class name and title.
- char g_szMainClass[] = "$[AppName + "Frame"]$";
- char g_szMainTitle[] = "$[AppTitle]$";
-
- // Main window handle.
- HWND g_hwndMain = 0;
-
- // Accelerator table handle.
- HACCEL g_haccel = 0;
-
- // Function prototypes.
- BOOL InitApplication (void);
- BOOL AboutDlg (void);
- BOOL MainOnCommand (int iItem);
-
- // Windows/dialog procedures.
- LRESULT CALLBACK _export MainWndProc (HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam);
- BOOL CALLBACK _export AboutDlgProc (HWND hdlg, UINT uiMessage, WPARAM wParam, LPARAM lParam);
-
- // $[PROTECT AppName + "UserDecls"]$
- // Global user definitions.
- // $[ENDPROTECT]$
-
-
- //
- // AboutDlg
- //
- // Show About dialog.
- //
-
- BOOL AboutDlg (void)
- {
- DLGPROC lpDlgProc;
- int iRetCode;
-
- // Create a modal dialog box
- #ifdef WIN32
- lpDlgProc = (DLGPROC) AboutDlgProc;
- #else
- lpDlgProc = (DLGPROC) MakeProcInstance((FARPROC) AboutDlgProc, g_hInstance);
- #endif
-
- // And really start the modal dialog!
- iRetCode = (int) DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_$[upper(AppName)]$ABOUT), g_hwndMain, (DLGPROC) lpDlgProc);
-
- #ifndef WIN32
- FreeProcInstance((FARPROC) lpDlgProc);
- #endif
-
- // Return code...
- return (BOOL) iRetCode;
- }
-
-
- //
- // AboutDlgProc
- //
- // About dialog procedure.
- //
-
- BOOL CALLBACK _export AboutDlgProc ( HWND hdlg, UINT uiMessage, WPARAM wParam, LPARAM lParam )
- {
- switch (uiMessage) {
-
- case WM_INITDIALOG:
- {
- // Just format the build date.
- char szBuild[80];
-
- lstrcpy(szBuild, __DATE__);
- lstrcat(szBuild, " ");
- lstrcat(szBuild, __TIME__);
-
- SetDlgItemText(hdlg, IDC_$[upper(AppName)]$ABOUTBUILD, szBuild);
- break;
- }
-
- case WM_COMMAND:
- {
- #ifdef WIN32
- int iCtlID = (int) LOWORD(wParam);
- #else
- int iCtlID = (int) wParam;
- #endif
- if (iCtlID == IDOK || iCtlID == IDCANCEL)
- EndDialog(hdlg, 0);
- break;
- }
-
- // $[PROTECT AppName + "AboutDlgCommands"]$
- // User AboutDlg Commands.
- // $[ENDPROTECT]$
-
- default:
- // Any other dialog message?
- return FALSE;
- }
-
- // We've handled it!
- return TRUE;
- }
-
-
- //
- // MainOnCommand
- //
- // Main window command handler.
- //
-
- BOOL MainOnCommand ( int iItem )
- {
- switch (iItem) {
-
- case IDM_FILEEXIT:
- // Destroy main window and quit application.
- DestroyWindow(g_hwndMain);
- break;
-
- case IDM_HELPABOUT:
- // Show about dialog box.
- AboutDlg();
- break;
-
- // $[PROTECT AppName + "MainCommands"]$
- // User Main Window Commands.
- // $[ENDPROTECT]$
-
- default:
- // Command not handled.
- return FALSE;
- }
-
- // Command has been handled.
- return TRUE;
- }
-
-
- //
- // MainWndProc
- //
- // Main window procedure.
- //
-
- LRESULT CALLBACK _export MainWndProc ( HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam )
- {
- switch (uiMessage) {
-
- case WM_COMMAND:
- {
- #ifdef WIN32
- WORD wCode = HIWORD(wParam);
- int iItem = (int) LOWORD(wParam);
- #else
- WORD wCode = HIWORD(lParam);
- int iItem = (int) wParam;
- #endif
- // See if it's from a menu bar or accelerator...
- if (wCode == 0 || wCode == 1)
- return (LRESULT) MainOnCommand(iItem);
- break;
- }
-
- case WM_DESTROY:
- // Terminate application.
- PostQuitMessage(0);
- break;
-
- // $[PROTECT AppName + "MainMessages"]$
- // User Main Window Message handling.
- // $[ENDPROTECT]$
-
- default:
- // Other messages processing.
- break;
- }
-
- // Default Windows dispatcher if not handled..
- return DefWindowProc(hwnd, uiMessage, wParam, lParam);
- }
-
-
- //
- // InitApplication
- //
- // Register main window class.
- //
-
- BOOL InitApplication (void)
- {
- WNDCLASS wc;
-
- // Load accelerator table.
- g_haccel = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDA_$[upper(AppName)]$ACCEL));
-
- // Check if window class is alredy registered.
- if (GetClassInfo(g_hInstance, g_szMainClass, &wc))
- return TRUE;
-
- // Fill out window class sttrcuture.
- wc.style = CS_DBLCLKS;
- wc.lpfnWndProc = (WNDPROC) MainWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = g_hInstance;
- wc.hIcon = 0;
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
- wc.lpszMenuName = MAKEINTRESOURCE(IDM_$[upper(AppName)]$MENU);
- wc.lpszClassName = g_szMainClass;
-
- return RegisterClass(&wc);
- }
-
-
- //
- // WinMain - Main Windows entry point.
- //
-
- int PASCAL WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )
- {
- // Initialize application.
- g_hInstance = hInstance;
- g_hPrevInstance = hPrevInstance;
- g_lpszCmdLine = lpszCmdLine;
- g_nCmdShow = nCmdShow;
-
- // Initialize this application instance.
- if (!InitApplication())
- return 0;
-
- // Create main window.
- g_hwndMain = CreateWindowEx(
- 0L, // Window extended style.
- g_szMainClass, // Registered class name.
- g_szMainTitle, // Window title.
- WS_OVERLAPPEDWINDOW, // Window style.
- CW_USEDEFAULT, // Horizontal position of window.
- CW_USEDEFAULT, // Vertical position of window.
- CW_USEDEFAULT, // Window width.
- CW_USEDEFAULT, // Window height.
- NULL, // Handle of parent window.
- NULL, // Handle of menu or child id.
- g_hInstance, // Application instance.
- NULL // Window creation data (none).
- );
-
- // Check if window has been properly created.
- if (g_hwndMain == NULL)
- return 0;
-
- // $[PROTECT AppName + "WinMain"]$
- // User Initialization stuff.
- // $[ENDPROTECT]$
-
- // Can show it!
- ShowWindow(g_hwndMain, g_nCmdShow);
- UpdateWindow(g_hwndMain);
-
- // Main message loop...
- MSG msg;
-
- while (GetMessage(&msg, 0, 0, 0)) {
- if (TranslateAccelerator(g_hwndMain, g_haccel, &msg) == 0) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
-
- // Return code from MSG struct...
- return (int) msg.wParam;
- }
-
-
- // end of $[upper(AppSrcFile)]$
- $[//*********************************]$
- $[//*** Application Resource file ***]$
- $[//*********************************]$
- $[output AppPath + AppRrcFile]$
- $[AppHeader(AppRrcFile, "/" + "/")]$
-
- #ifndef __$[upper(AppName)]$_RC
- #define __$[upper(AppName)]$_RC
-
- // Specific includes.
- #include "$[AppHdrFile]$"
-
- // Application icon.
- //$[AppName]$Icon ICON $[AppName]$.ico
-
- // $[PROTECT AppName + "UserResources"]$
- // User Resources.
- // $[ENDPROTECT]$
-
- //
- // Main window menu.
- //
-
- IDM_$[upper(AppName)]$MENU MENU
- BEGIN
-
- POPUP "&File"
- BEGIN
- // $[PROTECT AppName + "UserFileMenuItems"]$
- // User File Menu items.
- // $[ENDPROTECT]$
- MENUITEM "E&xit\aAlt+F4", IDM_FILEEXIT
- END
-
- // $[PROTECT AppName + "UserPopupMenus"]$
- // User Popup Menus.
- // $[ENDPROTECT]$
-
- POPUP "&Help"
- BEGIN
- // $[PROTECT AppName + "UserHelpMenuItems"]$
- // User Help Menu Items.
- // $[ENDPROTECT]$
- MENUITEM "&About $[AppName]$...", IDM_HELPABOUT
- END
-
- END
-
-
- //
- // Accelerator table.
- //
-
- IDA_$[upper(AppName)]$ACCEL ACCELERATORS
- BEGIN
- // $[PROTECT AppName + "UserAccelerators"]$
- // User Accelerators.
- // $[ENDPROTECT]$
- "Q", IDM_FILEEXIT, VIRTKEY, CONTROL
- END
-
-
- //
- // Dialogs.
- //
-
- IDD_$[upper(AppName)]$ABOUT DIALOG 50, 50, 234, 133
- STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
- CAPTION "About $[AppName]$"
- FONT 8, "MS Sans Serif"
- BEGIN
- CONTROL "$[AppName]$Icon", -1, "STATIC", SS_ICON | WS_CHILD | WS_VISIBLE, 4, 4, 18, 20
- CONTROL "$[AppTitle]$", -1, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 28, 6, 150, 8
- CONTROL "Version", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP, 28, 16, 26, 8
- CONTROL "$[AppVersid]$", -1, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 55, 16, 122, 8
- CONTROL "$[AppCopyright]$", -1, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 28, 26, 200, 8
- CONTROL "This product is licensed to:", -1, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 28, 41, 200, 8
- CONTROL "(UNREGISTERED)", IDC_$[upper(AppName)]$ABOUTNAME, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 28, 52, 200, 8
- CONTROL "", IDC_$[upper(AppName)]$ABOUTCOMPANY, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 28, 62, 200, 8
- CONTROL "", -1, "static", SS_BLACKRECT | WS_CHILD | WS_VISIBLE, 28, 77, 200, 1
- CONTROL "$[AppInfo]$", -1, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 28, 80, 200, 32
- CONTROL "Build date:", -1, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 28, 119, 38, 8
- CONTROL "", IDC_$[upper(AppName)]$ABOUTBUILD, "STATIC", SS_LEFT | SS_NOPREFIX | WS_CHILD | WS_VISIBLE | WS_GROUP, 70, 119, 157, 8
- CONTROL "OK", IDOK, "BUTTON", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 182, 4, 46, 14
- CONTROL "", -1, "static", SS_BLACKRECT | WS_CHILD | WS_VISIBLE, 28, 115, 200, 1
- END
-
-
- #endif // __$[upper(AppName)]$_RC
-
- // end of $[upper(AppRrcFile)]$
- $[//******************************************]$
- $[//*** Application Module Definition file ***]$
- $[//******************************************]$
- $[output AppPath + AppDefFile]$
- NAME $[AppName]$
- DESCRIPTION '$[AppName]$ Application'
- STUB 'WINSTUB.EXE'
- EXETYPE WINDOWS
- $[if AppGenDlg.Target.Select == 0 // Only for Windows 3.x]$
- CODE PRELOAD MOVEABLE DISCARDABLE
- DATA PRELOAD FIXED MULTIPLE
- HEAPSIZE 8192
- STACKSIZE 8192
- $[else]$
- SUBSYSTEM 4.0
- $[endif // Win16/Win32]$
- $[// *** Close All Output! ***]$
- $[output ""]$
- $[// *** Remember Application Definition ***]$
- $[if (!saveitem(SaveFile, AppGenDlg))]$
- $[msgbox("Error", "The dialog settings could not be saved to " + SaveFile, 16)]$
- $[endif]$
-